package com.ruoyi.monitor.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.monitor.domain.SysMsgModel;
import com.ruoyi.monitor.service.ISysMsgModelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 邮件模板Controller
 * 
 * @author xzx
 * @date 2023-02-23
 */
@RestController
@RequestMapping("/monitor/model")
public class SysMsgModelController extends BaseController
{
    @Autowired
    private ISysMsgModelService sysMsgModelService;

    /**
     * 查询邮件模板列表
     */
    @PreAuthorize("@ss.hasPermi('monitor:model:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMsgModel sysMsgModel)
    {
        startPage();
        List<SysMsgModel> list = sysMsgModelService.selectSysMsgModelList(sysMsgModel);
        return getDataTable(list);
    }

    /**
     * 导出邮件模板列表
     */
    @PreAuthorize("@ss.hasPermi('monitor:model:export')")
    @Log(title = "邮件模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMsgModel sysMsgModel)
    {
        List<SysMsgModel> list = sysMsgModelService.selectSysMsgModelList(sysMsgModel);
        ExcelUtil<SysMsgModel> util = new ExcelUtil<SysMsgModel>(SysMsgModel.class);
        util.exportExcel(response, list, "邮件模板数据");
    }

    /**
     * 获取邮件模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('monitor:model:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysMsgModelService.selectSysMsgModelById(id));
    }

    /**
     * 新增邮件模板
     */
    @PreAuthorize("@ss.hasPermi('monitor:model:add')")
    @Log(title = "邮件模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMsgModel sysMsgModel)
    {
        return toAjax(sysMsgModelService.insertSysMsgModel(sysMsgModel));
    }

    /**
     * 修改邮件模板
     */
    @PreAuthorize("@ss.hasPermi('monitor:model:edit')")
    @Log(title = "邮件模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMsgModel sysMsgModel)
    {
        return toAjax(sysMsgModelService.updateSysMsgModel(sysMsgModel));
    }

    /**
     * 删除邮件模板
     */
    @PreAuthorize("@ss.hasPermi('monitor:model:remove')")
    @Log(title = "邮件模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysMsgModelService.deleteSysMsgModelByIds(ids));
    }
}
